<?php ob_start();?>
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
include($root.'/standart/head.php');
include($root.'/standart/dateHeader.php');
include($root.'/standart/checkUser.php');
$db = connect();
$bgn_date = "";
$end_date = "";
$tmpDate = $_GET["begin_date"];
if($tmpDate <> ""){
	list($gun,$ay,$yil) = explode('/',$tmpDate);
	$bgn_date = $yil.'-'.$ay.'-'.$gun;
}
$tmpDate = $_GET["end_date"];
if($tmpDate <> ""){
	list($gun,$ay,$yil) = explode('/',$tmpDate);
	$end_date = $yil.'-'.$ay.'-'.$gun;
}
$userId = $_GET["user_id"];
$stmt ="SELECT ORDERS.ID,GEVEZE_USER.NAME,GEVEZE_USER.SURNAME,ORDERS.ORDER_DATE,
ORDERS.PAYMENT_TYPE,ADDRESS.ADDRESS_1,ORDERS.NOTES,ORDERS.TOTAL_AMOUNT FROM ORDERS
LEFT OUTER JOIN GEVEZE_USER ON
ORDERS.USER_ID=GEVEZE_USER.ID
LEFT OUTER JOIN ADDRESS ON
ORDERS.SHIPPING_ADDRESS=ADDRESS.ID
WHERE CANCEL = 0";
if($bgn_date <> "" or $end_date <> "" or $userId <> ""){
	$stmt = $stmt." WHERE ORDERS.ID IS NOT NULL";
}
		if($bgn_date <> ""){
			$stmt = $stmt." AND ORDER_DATE > '$bgn_date'";
		}
		if($end_date <> ""){
			$stmt = $stmt." AND ORDER_DATE < '$end_date'";
		}
		if($userId <> ""){
			$stmt = $stmt." AND ORDERS.USER_ID = '$userId'";
		}
$res = $db->query($stmt) or die($stmt."<br/><br/>".mysql_error());
	?>
	<table class="table table-striped table-bordered table-hover" id="dataTables-example">
		<thead>
        	<tr>
        		<th style="display:none;">Sipariş No</th>
                <th>İsim</th>
                <th>Soyisim</th>
                <th>Sipariş Tarihi</th>
				<th>Ödeme Tipi</th>
                <th>Gönderim Adresi</th>
                <th>Sipariş Notu</th>
                <th>Sipariş Tutarı</th>
            </tr>
		</thead>
        <tbody>
        <?php $odd = true; ?>
       	<?php while($row = $res->fetch_assoc()){?>
        	<tr class="<?php echo $odd ? "odd" : "even";?> " style="cursor: pointer;">
	            <td style="display:none;"><?php echo $row["ID"];?></td>
	            <td><?php echo $row["NAME"];?></td>
	            <td><?php echo $row["SURNAME"];?></td>
                <td><?php echo date("m/d/Y",strtotime($row["ORDER_DATE"]));?></td>
                <td><?php echo $row["PAYMENT_TYPE"];?></td>
                <td><?php echo $row["ADDRESS_1"];?></td>
                <td><?php echo $row["NOTES"];?></td>
                <td style="text-align: right;"><?php echo $row["TOTAL_AMOUNT"]; ECHO ' TL';?></td>
			</tr>
			<?php $odd = !$odd;?>
		<?php }?>
		<?php if(isset($_GET['report'])){?>
			<tfoot>
	            <tr>
	            	<td style="display: none;"></td>
	            	<td style="display: none;"></td>
	            	<td style="display: none;"></td>
	                <th colspan="6" style="text-align:right">Toplam:</th>
	                <th></th>
	            </tr>
	        </tfoot>
		<?php }?>
		</tbody>
     </table>
	<?php 
$res->close();
disconnect($db);
?>
<?php ob_end_flush(); ?>